package com.cskaoyan.service.admin.impl;

import com.cskaoyan.bean.vo.statistics.*;
import com.cskaoyan.mapper.MarketOrderGoodsMapper;
import com.cskaoyan.mapper.MarketOrderMapper;
import com.cskaoyan.mapper.MarketUserMapper;
import com.cskaoyan.service.admin.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Yan Dexuan
 * @since 2022/06/26 13:51
 */

@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    MarketUserMapper marketUserMapper;

    @Autowired
    MarketOrderMapper marketOrderMapper;

    @Autowired
    MarketOrderGoodsMapper marketOrderGoodsMapper;

    /**
     * 用户统计，显示用户增长数量，最后登录日期。
     * @return com.cskaoyan.bean.vo.statistics.UserStatisticsVo
     * @author Yan Dexuan
     * @since 2022/06/26 16:10
     */
    @Override
    public UserStatisticsVo showUser() {

        List<UserRowsVo> userRowsVos = marketUserMapper.selectCountGroupByTime();

        UserStatisticsVo userStatisticsVo = new UserStatisticsVo();
        userStatisticsVo.setRows(userRowsVos);

        return userStatisticsVo;
    }

    /**
     * 订单统计功能，显示订单量，下单用户，订单总额以及客单价。
     * @return com.cskaoyan.bean.vo.statistics.OrderStatisticsVo
     * @author Yan Dexuan
     * @since 2022/06/26 20:17
     */
    @Override
    public OrderStatisticsVo showOrder() {

        List<OrderRowsVo> orderRowsVos = marketOrderMapper.selectCountGroupByTime();

        OrderStatisticsVo orderStatisticsVo = new OrderStatisticsVo();
        orderStatisticsVo.setRows(orderRowsVos);



        /*List<OrderRowsVo> orderRowsVos = new ArrayList<>();
        OrderRowsVo orderRowsVo = new OrderRowsVo();
        orderRowsVo.setDay(new Date());
        orderRowsVo.setOrders(100);
        orderRowsVo.setCustomers(50);
        orderRowsVo.setPcr(100.0);
        orderRowsVo.setAmount(10000.0);
        orderRowsVos.add(orderRowsVo);
        orderStatisticsVo.setRows(orderRowsVos);*/

        return orderStatisticsVo;

    }

    /**
     * 商品统计功能，显示订单量，下单货品数量以及下单货品总额。
     * @return com.cskaoyan.bean.vo.statistics.GoodsStatisticsVo
     * @author Yan Dexuan
     * @since 2022/06/26 20:16
     */
    @Override
    public GoodsStatisticsVo showGoods() {

        List<GoodsRowsVo> goodsRowsVos = marketOrderGoodsMapper.selectCountGroupByTime();

        GoodsStatisticsVo goodsStatisticsVo = new GoodsStatisticsVo();
        goodsStatisticsVo.setRows(goodsRowsVos);

        return goodsStatisticsVo;

    }
}
